using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Diagnostics;

namespace Minimal.Web
{
    /// <summary>
    /// Configuration settings for the Minimal.Web.QueryString component.
    /// </summary>
    internal class QueryStringConfiguration
        : ConfigurationSection
    {
        
        /// <summary>
        /// A secret key to use for encryption of the query string.
        /// </summary>
        [ConfigurationProperty("encryptionKey", DefaultValue="abcdefgh")]
        public string EncryptionKey
        {
            get
            {
                return (string)this["encryptionKey"];
            }
            set
            { 
                this["encryptionKey"] = value;
            }
        }
        

        
        /// <summary>
        /// The key to use in the query string for the encrypted data.
        /// </summary>
        /// <example>When the default value "data" is used the query string will look
        /// like follows: http://www.example.com/index.aspx?data=%ifjowedmnf==...</example>
        [ConfigurationProperty("encryptedQueryStringKey", DefaultValue="data")]
        public string EncryptedQueryStringKey
        {
            get
            {
                return (string)this["encryptedQueryStringKey"];
            }
            set
            {
                this["encryptedQueryStringKey"] = value;
            }
        }
        

        
        /// <summary>
        /// The key to use for the metadata in the query string.
        /// </summary>
        /// <example>In the case when the default value "meta" is used the url
        /// could look something like: ...Default.aspx?meta=%kjdfo...</example>
        [ConfigurationProperty("metadataKey", DefaultValue="meta")]
        public string MetadataKey
        {
            get
            {
                return (string)this["metadataKey"];
            }
            set
            {
                this["metadataKey"] = value;
            }
        }
        
        
        
        /// <summary>
        /// Gets or sets whether the query string should be encrypted.
        /// </summary>
        [ConfigurationProperty("encryptQueryString", DefaultValue=true)]
        public bool EncryptQueryString
        {
            get
            {
                return (bool)this["encryptQueryString"];
            }
            set
            {
                this["encryptQueryString"] = value;
            }
        }
        

        
        /// <summary>
        /// Gets or sets whether metadata should be included in the query string,
        /// metadata is required for automatic parsing of query strings where no type
        /// is supplied to the parse method.
        /// </summary>
        [ConfigurationProperty("includeMetadata", DefaultValue=true)]
        public bool IncludeMetadata
        {
            get
            {
                return (bool)this["includeMetadata"];
            }
            set
            {
                this["includeMetadata"] = value;
            }
        }
        

        
        /// <summary>
        /// Settings for parameters that should be excluded from the excluded query
        /// string.
        /// </summary>
        [ConfigurationProperty("parameterExclusions")]
        public ParameterExclusions ParameterExclusions
        {
            get
            {
                return (ParameterExclusions)this["parameterExclusions"];
            }
            set
            {
                this["parameterExclusions"] = value;
            }
        }
        

        
        /// <summary>
        /// Options for the parsing of query strings.
        /// </summary>
        [ConfigurationProperty("parseOptions")]
        public ParseOptions ParseOptions
        {
            [System.Diagnostics.DebuggerStepThroughAttribute]
            get
            {
                return (ParseOptions)this["parseOptions"];
            }
            [System.Diagnostics.DebuggerStepThroughAttribute]
            set
            {
                this["parseOptions"] = value;
            }
        }
        

        
        [DebuggerBrowsable(DebuggerBrowsableState.Never)]
        private static QueryStringConfiguration _instance;

        /// <summary>
        /// Gets an instance of the configuration section, getting the settings from the configuration
        /// file or the default settings.
        /// </summary>
        public static QueryStringConfiguration Instance
        {
            get
            {
                if (_instance == null)
                {
                    QueryStringConfiguration section = (QueryStringConfiguration)ConfigurationManager.GetSection("queryStringConfiguration");
                    if (section == null)
                    {
                        section = new QueryStringConfiguration();
                    }
                    _instance = section;
                }
                return _instance;
            }
        }
	    
    }
}
